package Test;

import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;

public class Test {
    public static void main(String[] args) {

    }

    public static void main2(String[] args) {
        ArrayList<String> arrayList = new ArrayList<>();
        arrayList.add("abd");
        arrayList.add("def");
        arrayList.add("github");
        arrayList.add("1234");
        arrayList.add("4567");
        //遍历ArrayList的方式
        System.out.println(arrayList);
        for(int i = 0; i < arrayList.size(); i++) {
            System.out.print(arrayList.get(i)+" ");
        }
        System.out.println();
        for (String s:
             arrayList) {
            System.out.print(s+" ");
        }
        System.out.println();

        Iterator<String> it = arrayList.iterator();
        //如果有下一个则打印下一个
        while(it.hasNext()) {
            //先走然后去走完后的值，在进行打印
            System.out.print(it.next()+" ");
        }
        System.out.println();

//        List<String> ret = arrayList.subList(0,2);
//        ret.set(0,"yxj");
//        System.out.println(ret);
    }

    public static void main1(String[] args) {
        ArrayList<String> arrayList = new ArrayList<>();
        arrayList.add("abd");
        arrayList.add("def");
        List<String> list = new ArrayList<>();
        list.add("hello");
        list.addAll(arrayList);
        list.remove(1);
        list.remove("hello");
        list.clear();
        System.out.println();
    }
}
